<?php
/**
 * Form Twibs
 * @author	Jeremy Lindblom
 */

namespace form;

function open($n,$a=array()){$a['id']=$a['name']=$n;return"<form".\html\attr($a).'>';}
function input($n,$t='text',$v='',$a=array()){$a['id']=$a['name']=$n;$a['type']=$t;if($v)$a['value']=$v;return\html\tag('input',0,$a);}
function select($n,$o=array(),$s='',$a=array(),$d=0){$a['id']=$a['name']=$n;return\html\tag('select',options($o,$s,$d),$a);}
function options(array$o,$s='',$d=0){if(is_string($d))$o=array(''=>$d)+$o;array_walk($o,'form\opt',$s);return join('',$o);}
function opt(&$v,$k,$s){@$a['value']=$k;if($s===$k)$a[$b='selected']=$b;$v=\html\tag('option',$v,$a);}
function textarea($n,$v='',$a=array()){$a['id']=$a['name']=$n;return\html\tag('textarea',$v,$a);}
function close(){return'</form>';}

/* Example Usage
echo form\open('jim');
echo form\input('name','text');
echo form\textarea('comment');
$options = array('R'=>'Red','B'=>'Blue','Y'=>'Yellow');
echo form\select('color',$options,'B',array(),'Please Select...');
echo form\close();
*/